package org.mrjbee.share.it.easy.server;

import java.util.HashMap;

import org.restlet.data.Status;
import org.restlet.resource.Get;
import org.restlet.resource.Post;
import org.restlet.resource.ResourceException;
import org.restlet.resource.ServerResource;

import com.google.appengine.api.oauth.OAuthRequestException;
import com.google.appengine.api.oauth.OAuthService;
import com.google.appengine.api.oauth.OAuthServiceFactory;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

public class ClipboardDataResource extends ServerResource {
	
	static private ClipboardData EMPTY = new ClipboardData("There is no data yet");
	static private HashMap<String, ClipboardData> clipboardDataPerUser = new HashMap<String, ClipboardData>();
	
	@Get("text")
	public synchronized String getData(){
		String userName = OAuthCheker.getUserName(true);
		ClipboardData clipboardData = clipboardDataPerUser.get(userName);
		if (clipboardData == null){
			clipboardData = EMPTY;
		}
		return clipboardData.getActualData();
	}
	
	
	@Post("text")
	public synchronized void storeData(String text){
		String userName = OAuthCheker.getUserName(true);
		clipboardDataPerUser.put(userName, new ClipboardData(text));
	}

}
